package com.process.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainActivity extends AppCompatActivity {
    public static final int port = 8080;
    public static final String host = "localhost";

     private static PrintWriter pw=null;
     private static BufferedReader br=null;
     private static Socket s;
     private ExecutorService  executorService = Executors.newSingleThreadExecutor();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    public void onClick(View view) {
//        executorService.execute(new Runnable() {
//            @Override
//            public void run() {
//                try {
////                    InetAddress inetAddress  = InetAddress.getLocalHost();
//                    //创建一个流套接字并将其连接到指定主机上的指定端口号
//                    s = new Socket(InetAddress.getByName("127.0.0.1") ,8080);
//                    pw =new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
//                    br =new BufferedReader(new InputStreamReader(s.getInputStream()));
//                    pw.print("链接网络服务");
//                } catch (IOException e) {
//                    e.printStackTrace();
//                    if (s != null ){
//                        try {
//                            s.close();
//                        } catch (IOException e1) {
//                            e1.printStackTrace();
//                        }
//                    }
//                }
//            }
//        });

    }


    @Override
    protected void onDestroy() {
        if (s != null ){
            try {
                s.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        executorService.shutdown();
        super.onDestroy();

    }
}
